package me.yushuai.wukong.base.entity;

import lombok.*;
import me.yushuai.wukong.common.domain.AbstractAudit;
import org.hibernate.Hibernate;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;

/**
 * 系统配置
 *
 * @author zhoushuai@189.cn
 * @since 2022-09-13
 */
@Getter
@Setter
@ToString
@Entity
@Table(name = "BAS_CONF_GROUP", indexes = {@Index(columnList = "GROUP_BIZ_ID")})
public class ConfGroup extends AbstractAudit implements Serializable {

    /**
     * 代码ID
     */
    @Id
    @Column(name = "GROUP_ID")
    private Long groupId;

    /**
     * 代码编码
     */
    @Column(name = "GROUP_BIZ_ID", updatable = false, nullable = false)
    private String bizId;

    /**
     * 中文描述
     */
    @Column(name = "GROUP_NAME_C")
    private String confNameC;

    /**
     * 英文描述
     */
    @Column(name = "GROUP_NAME_E")
    private String confNameE;

    /**
     * 用于为配置生成序号，序号仅用作唯一标识，不用作排序使用。
     */
    @Column(name = "LAST_SEQUENCE")
    private Integer lastSequence;

    /**
     * 长度
     */
    @Column(name = "GROUP_LENGTH")
    private Integer confLength;

    /**
     * 代码类型
     */
    @Column(name = "CODE_TYPE")
    private String codeType;

    /**
     * 是否可修改
     */
    @Type(type = "yes_no")
    @Column(name = "GROUP_MODIFIED")
    private Boolean modified;

    /**
     * 自定义1
     */
    @Column(name = "UDF1")
    private String udf1;

    /**
     * 自定义2
     */
    @Column(name = "UDF2")
    private String udf2;

    /**
     * 自定义3
     */
    @Column(name = "UDF3")
    private String udf3;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
            return false;
        }
        ConfGroup confGroup = (ConfGroup) o;
        return groupId != null && Objects.equals(groupId, confGroup.groupId);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}